- Two numbers are considered as very different if they differ by more than 10. Write a complete C++ program using the main function given below. Write a C++ function called areVeryDifferent that determines whether two integers are very different.
For example, your function could be used in the following program.
int main() {
int x = 4, y = 10, z = -4;
if (areVeryDifferent(x, y)) cout << "x and y are very different" << endl;
if (areVeryDifferent(x, z)) cout << "x and z are very different" << endl;
if (areVeryDifferent(y, z)) cout << "y and z are very different" << endl;
return 0;
}
The output from this program would be:
y and z are very different
- Write a complete C++ program using the main function given below. Write a function called countChange that uses four parameters q, d, n, and p and converts the value of q quarters, d dimes, n nickels, and p cents into dollars.
For example, a program that uses the function countChange follows.
int main() {
int q = 10, d = 5, n = 1, p = 2;
double x = countChange(q, d, n, p);
cout << "You have $" << x << endl;
}
It should print:
You have $3.07
- Write a complete C++ program using the main function given below. Write a function called quadratic that calculates the value of a quadratic function ax^2 + bx + c.
For example, a program that uses the function quadratic follows.
int main() {
double a = 1.0, b = 2.2, c = 1.21, x = 0.1;
cout << quadratic(a, b, c, x) << endl;
return 0;
}
It should print:
1.44
- Write a complete C++ program using the main function given below. Write a function called toSeconds that uses three parameters d, h and m, and converts d days, h hours and m minutes into seconds.
For example, a program that uses the function toSeconds follows.
int main() {
int d = 5, h = 12, m = 30;
cout << toSeconds(d, h, m) << endl;
return 0;
}
It should print:
477000
- Write a complete C++ program using the main function given below. Write a function called minMaxMath that uses three parameters a, b and c, and prints
- the sum of the three numbers
- the product of the three numbers
- the largest of the three numbers
- the smallest of the three numbers
For example, a program that uses the function minMaxMath follows.
int main() {
int a = 7, b = 2, c = 4;
minMaxMath(a, b, c);
return 0;
}
It should print:
The sum is 13
The product is 56
The largest number is 7
The smallest number is 2